package com.ypd.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ypd.common.core.domain.R;
import com.ypd.shop.domain.Properties;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ypd.common.annotation.Log;
import com.ypd.common.core.controller.BaseController;
import com.ypd.common.core.domain.AjaxResult;
import com.ypd.common.enums.BusinessType;
import com.ypd.shop.domain.PropertyFavorites;
import com.ypd.shop.service.IPropertyFavoritesService;
import com.ypd.common.utils.poi.ExcelUtil;
import com.ypd.common.core.page.TableDataInfo;

/**
 * 我的收藏Controller
 * 
 * @author lin
 * @date 2024-12-06
 */

@RestController
@RequestMapping("/shop/favorites")
@Api(tags = "我的收藏Controller")
public class PropertyFavoritesController extends BaseController
{
    @Autowired
    private IPropertyFavoritesService propertyFavoritesService;

    /**
     * 查询我的收藏列表
     */
    @ApiOperation("查询我的收藏列表")
    //@PreAuthorize("@ss.hasPermi('shop:favorites:list')")
    @GetMapping("/list")
    public TableDataInfo list(Properties properties)
    {
        startPage();
        List<Properties> list = propertyFavoritesService.selectPropertyFavoritesList(properties);
        return getDataTable(list);
    }


    /**
     * 获取我的收藏详细信息
     */
    @ApiOperation("获取我的收藏详细信息")
    //@PreAuthorize("@ss.hasPermi('shop:favorites:query')")
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return success(propertyFavoritesService.selectPropertyFavoritesByFavoriteId(favoriteId));
    }

    /**
     * 新增我的收藏
     */
    @ApiOperation("新增我的收藏")
    //@PreAuthorize("@ss.hasPermi('shop:favorites:add')")
    @Log(title = "我的收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyFavorites propertyFavorites)
    {
        return toAjax(Math.toIntExact(propertyFavoritesService.insertPropertyFavorites(propertyFavorites)));
    }

    /**
     * 修改我的收藏
     */
    @ApiOperation("修改我的收藏")
    //@PreAuthorize("@ss.hasPermi('shop:favorites:edit')")
    @Log(title = "我的收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyFavorites propertyFavorites)
    {
        return toAjax(propertyFavoritesService.updatePropertyFavorites(propertyFavorites));
    }

    /**
     * 删除我的收藏
     */
    @ApiOperation("删除我的收藏")
    //@PreAuthorize("@ss.hasPermi('shop:favorites:remove')")
    @Log(title = "我的收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(propertyFavoritesService.deletePropertyFavoritesByFavoriteIds(favoriteIds));
    }

    /**
     * 根据店铺id查找是否在收藏列表中
     */
    @ApiOperation("根据店铺id查找是否在收藏列表中")
    //@PreAuthorize("@ss.hasPermi('shop:favorites:query')")
    @GetMapping("/query/{propertyId}")
    public AjaxResult query(@PathVariable("propertyId") Long propertyId)
    {
        //根据店铺id查找是否在收藏列表中
        return success(propertyFavoritesService.queryByPropertyId(propertyId));
    }
}
